#!/bin/sh

# 01.06.2005 Volker Quetschke
# Tests for dmake function macros - part 2.
# (issue 36027, issue 37053, issue 37491)

: ${DMAKEPROG:=dmake}
file1="mymakefile.mk"
tmpfiles="$file1"

trap '{ echo "trapped signal - removing temporary files" ; rm -rf $tmpfiles ; }' 1 2 3 15

trap 'rm -rf $tmpfiles' 1 2 3 15 

# Remember to quote variables in generated makefiles( $ -> \$ ).
cat > $file1 <<EOT
# Testing function macros
SHELL*:=/bin/sh 
SHELLFLAGS*:=-ce

TEST1:=a b c
PAT:=Z

all:
	+@echo -e '\n\$\$(shell ...) section'
	+test ":123:" = ":\$(shell echo 123  ):"
	+test ":123:" = ":\$(shell   \
     echo 123  ):"
	+test ":123:" = ":\$(shell echo \
     123  ):"

	+@echo -e '\n\$\$(sort ...) section'
	+test ":a b c:" = ":\$(sort c  a b   ):"
	+test ":a b c:" = ":\$(sort\
     c  a b   ):"
	+test ":a b c:" = ":\$(sort   c \
    a b   ):"

	+@echo -e '\n\$\$(strip ...) section'
	+test ":c a b:" = ":\$(strip    c   a b   ):"
	+test ":c a b:" = ":\$(strip    c \
     a b   ):"

	+@echo -e '\n\$\$(subst ...) section' 
	+test ":aZbZc:" = ":\$(subst,\$(SPACECHAR),\$(PAT) \$(TEST1)):"
	+test ":aZbZc:" = ":\$(subst,%Z*Z%,\$(PAT) \$(TEST1:s/ /%Z*Z%/)):"
	+test ":aZbZc:" = ":\$(subst,Y,\$(PAT)       aYbYc         ):"
	+test ":aZbZc:" = ":{\$(subst,Y,Z       aYbYc         )}:"
# Undefined
#	+test ":Should error out:BUG:\$(subst, ,\$(PAT) \$(TEST1)):"

	+@echo -e '\n\$\$(uniq ...) section'
	+test ":a b c:" = ":\$(uniq    c   a b c ):"
	+test ":a b c:" = ":\$(uniq    c   \
     a b c ):"

EOT

${DMAKEPROG} -r -f $file1
result=$?

test $result -eq 0 && echo "Success - Cleaning up" && rm -f ${tmpfiles}
test $result -ne 0 && echo "Failure!"
exit $result